package com.cswangdao.service.impl;

import com.cswangdao.domain.dto.IssuePageDTO;
import com.cswangdao.domain.model.MarketIssue;
import com.cswangdao.mapper.MarketIssueMapper;
import com.cswangdao.result.PageResult;
import com.cswangdao.service.IssueService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Transactional
public class IssueServiceImpl implements IssueService {
    @Autowired
    private MarketIssueMapper issueMapper;

    @Override
    public PageResult<MarketIssue> pageQueryInfo(IssuePageDTO pageDTO) {
        PageHelper.startPage(pageDTO.getPage(),pageDTO.getLimit());
        Page<MarketIssue> page = issueMapper.pageQueryInfo(pageDTO);
        PageResult<MarketIssue> result = PageResult.result(page);
       return result;
    }

    @Override
    public void updateById(MarketIssue issue) {
        issueMapper.updateById(issue);
    }

    @Override
    public MarketIssue addIssue(MarketIssue issue) {
        issue.setAddTime(new Date());
        issue.setUpdateTime(new Date());
        issueMapper.addIssue(issue);
        return issue;
    }

    @Override
    public void deleteById(Integer id) {
        issueMapper.deleteById(id);
    }

}
